
<style type="text/css">

#picdata_main ul { list-style: none; width: 600px; margin: 0px; padding: 0px; }
#picdata_main ul li { float: left; margin: 10px; padding: 10px 10px; width: 110px; height: 120px; 
	text-align: center; background: #f7f7f7; }

</style>


<div id="picdata_main">
	<h2>上传图片</h2>
	<%= form_for @picdata, :url => '/admin/picdata/create', :html => { :multipart => true } do |form| %>
	  <%= form.file_field :pic %>
	  <br/><%= form.submit :class=>'btn btn-primary' %> 
	  	<% if(flash[:result] != nil) %><span id="result" class="label label-info"><%=flash[:result]%></span><% end %>
	<% end %>

	<h2>上传列表</h2>
	<%if(request[:notice]=='delete')%>
	&nbsp;&nbsp;&nbsp;&nbsp;<span class="label label-success">删除成功</span>
	<%end%>
	<ul>
	<% @piclist.each do |pic|%>
		<li><a href="<%=pic.pic.url%>" target="_blank"><%= image_tag pic.pic.url(:thumb) %></a>
			<br/><a href="javascript:void(__delete(<%=pic.id%>));">删除</a>
		</li>
	<% end %>
	</ul>
	<div style="clear:both"></div>
</div>
<div class='flickr_pagination'><%= will_paginate @piclist, :renderer => 'PostLinkRenderer', :previous_label => '上页', :next_label => '下页', :url => '/admin/picdata/' %></div>
<script type="text/javascript">
$().ready(function(){
	$.ajaxSetup({  
	    beforeSend: function(xhr) {  
	        xhr.setRequestHeader("X-CSRF-Token", $("meta[name=\"csrf-token\"]").attr("content"));  
	    }  
	});	
});

function __delete(id) {
	if(confirm('确定要删除吗?')) {
		$.ajax({
			type : 'DELETE',
			url : '/admin/picdata/delete',
			data : { id: id },
			success: function(d){
				if(d == 1) {
					location.href = '/admin/picdata?notice=delete';
				} else {
					alert('删除失败，请重新尝试。');
				}
			}	
		});
	}
}
</script>
